package com.xiaoxx.controller.sys;


import com.xiaoxx.common.result.R;
import com.xiaoxx.model.vo.sys.SysRedisKeyVo;
import com.xiaoxx.service.SysRedisKeyService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author HX
 * @since 2023-08-17
 */
@RestController
@RequestMapping("/api/sys/redisKey")
public class SysRedisKeyController {
    @Autowired
    private SysRedisKeyService sysRedisKeyService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ApiOperation(value = "缓存列表")
    @ApiResponses(value = {@ApiResponse(response = SysRedisKeyVo.class, code = 200, message = "响应成功")})
    public R<List<SysRedisKeyVo>> list() {
        return R.success(sysRedisKeyService.listRedisKeys());
    }

    @RequestMapping(value = "/listKeys", method = RequestMethod.GET)
    @ApiOperation(value = "键名列表")
    @ApiResponses(value = {@ApiResponse(response = SysRedisKeyVo.class, code = 200, message = "响应成功")})
    public R<List<String>> listKeys(String key) {
        return R.success(sysRedisKeyService.listRedisKeyNames(key));
    }

    @RequestMapping(value = "/getRedisValue", method = RequestMethod.GET)
    @ApiOperation(value = "键值")
    @ApiResponses(value = {@ApiResponse(response = SysRedisKeyVo.class, code = 200, message = "响应成功")})
    public R<Map<String, Object>> getRedisValue(@RequestParam String key) {
        return R.success(sysRedisKeyService.getRedisValue(key));
    }

    @RequestMapping(value = "/del", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除")
    @ApiResponses(value = {@ApiResponse(response = SysRedisKeyVo.class, code = 200, message = "响应成功")})
    public R<Boolean> del(@RequestParam String key) {
        return R.success(sysRedisKeyService.del(key));
    }
}

